package cn.itsy.dao.log;

import cn.itsy.utils.Syslog;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: MisterGay
 * @date: 2019-06-11 9:02
 */
@Repository(value = "logDaoimpl")
public class LogDaoimpl implements LogDao {
    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public void saveLog(String sql, Syslog syslog) {
        this.jdbcTemplate.update(sql, syslog.getId(), syslog.getVisitTime(), syslog.getUsername(),
                syslog.getIp(), syslog.getUrl(), syslog.getExecutionTime(), syslog.getMethod());
    }

    @Override
    public List<Syslog> querySyslogAll(String sql) {
        List<Syslog> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Syslog>(Syslog.class));
        return query;
    }
}
